home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / sprite.X11R3 / spriteBW2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-13  |  7.7 KB  |  302 lines

  1. /*-
  2.  * spriteBW2.c --
  3.  *    Functions for handling the sprite BWTWO board.
  4.  *
  5.  * Copyright (c) 1987 by the Regents of the University of California
  6.  *
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  *
  15.  *
  16.  */
  17. #ifndef lint
  18. static char rcsid[] =
  19.     "$Header: /mic/X11R3/src/cmds/Xsp/ddx/sprite/RCS/spriteBW2.c,v 1.8 89/11/18 20:56:37 tve Exp $ SPRITE (Berkeley)";
  20. #endif lint
  21.  
  22. #include    "spriteddx.h"
  23. #include    "os.h"
  24. #include    "resource.h"
  25.  
  26. #include    <kernel/devVid.h>
  27. #include    <sys.h>
  28. #include    <kernel/vmSunConst.h>
  29.  
  30. /*
  31.  * From <sundev/bw2reg.h>
  32.  */
  33. #define BW2_FBSIZE    (128*1024)
  34. #define BW2_WIDTH     1152
  35. #define BW2_HEIGHT    900
  36.  
  37. /*
  38.  * Regular bw2 board.
  39.  */
  40. typedef struct bw2 {
  41.     unsigned char    image[BW2_FBSIZE];          /* Pixel buffer */
  42. } BW2, BW2Rec, *BW2Ptr;
  43.  
  44. /*-
  45.  *-----------------------------------------------------------------------
  46.  * spriteBW2SaveScreen --
  47.  *    Disable the video on the frame buffer to save the screen.
  48.  *
  49.  * Results:
  50.  *    TRUE.
  51.  *
  52.  * Side Effects:
  53.  *    Video enable state changes.
  54.  *
  55.  *-----------------------------------------------------------------------
  56.  */
  57. static Bool
  58. spriteBW2SaveScreen (pScreen, on)
  59.     ScreenPtr      pScreen;
  60.     int          on;
  61. {
  62.     if (on != SCREEN_SAVER_ON) {
  63.     SetTimeSinceLastInputEvent();
  64.     screenSaved = FALSE;
  65.     Sys_EnableDisplay(TRUE);
  66.     } else {
  67.     screenSaved = TRUE;
  68.     Sys_EnableDisplay (FALSE);
  69.     }
  70.  
  71.     return TRUE;
  72. }
  73.  
  74. /*-
  75.  *-----------------------------------------------------------------------
  76.  * spriteBW2CloseScreen --
  77.  *    called to ensure video is enabled when server exits.
  78.  *
  79.  * Results:
  80.  *    Screen is unsaved.
  81.  *
  82.  * Side Effects:
  83.  *    None
  84.  *
  85.  *-----------------------------------------------------------------------
  86.  */
  87. /*ARGSUSED*/
  88. static Bool
  89. spriteBW2CloseScreen(i, pScreen)
  90.     int        i;
  91.     ScreenPtr    pScreen;
  92. {
  93.     return ((* pScreen->SaveScreen)(pScreen, SCREEN_SAVER_OFF));
  94. }
  95.  
  96. /*-
  97.  *-----------------------------------------------------------------------
  98.  * spriteBW2ResolveColor --
  99.  *    Resolve an RGB value into some sort of thing we can handle.
  100.  *    Just looks to see if the intensity of the color is greater than
  101.  *    1/2 and sets it to 'white' (all ones) if so and 'black' (all zeroes)
  102.  *    if not.
  103.  *
  104.  * Results:
  105.  *    *pred, *pgreen and *pblue are overwritten with the resolved color.
  106.  *
  107.  * Side Effects:
  108.  *    see above.
  109.  *
  110.  *-----------------------------------------------------------------------
  111.  */
  112. static void
  113. spriteBW2ResolveColor(pred, pgreen, pblue, pVisual)
  114.     unsigned short    *pred;
  115.     unsigned short    *pgreen;
  116.     unsigned short    *pblue;
  117.     VisualPtr        pVisual;
  118. {
  119.     *pred = *pgreen = *pblue = 
  120.         (((39L * (int)*pred +
  121.            50L * (int)*pgreen +
  122.            11L * (int)*pblue) >> 8) >= (((1<<8)-1)*50)) ? ~0 : 0;
  123. }
  124.  
  125. /*-
  126.  *-----------------------------------------------------------------------
  127.  * spriteBW2CreateColormap --
  128.  *    create a bw colormap
  129.  *
  130.  * Results:
  131.  *    None
  132.  *
  133.  * Side Effects:
  134.  *    allocate two pixels
  135.  *
  136.  *-----------------------------------------------------------------------
  137.  */
  138. void
  139. spriteBW2CreateColormap(pmap)
  140.     ColormapPtr    pmap;
  141. {
  142.     int    red, green, blue, pix;
  143.  
  144.     /* this is a monochrome colormap, it only has two entries, just fill
  145.      * them in by hand.  If it were a more complex static map, it would be
  146.      * worth writing a for loop or three to initialize it */
  147.  
  148.     /* this will be pixel 0 */
  149.     pix = 0;
  150.     red = green = blue = ~0;
  151.     AllocColor(pmap, &red, &green, &blue, &pix, 0);
  152.  
  153.     /* this will be pixel 1 */
  154.     red = green = blue = 0;
  155.     AllocColor(pmap, &red, &green, &blue, &pix, 0);
  156.  
  157. }
  158.  
  159. /*-
  160.  *-----------------------------------------------------------------------
  161.  * spriteBW2DestroyColormap --
  162.  *    destroy a bw colormap
  163.  *
  164.  * Results:
  165.  *    None
  166.  *
  167.  * Side Effects:
  168.  *    None
  169.  *
  170.  *-----------------------------------------------------------------------
  171.  */
  172. /*ARGSUSED*/
  173. void
  174. spriteBW2DestroyColormap(pmap)
  175.     ColormapPtr    pmap;
  176. {
  177. }
  178.  
  179. /*-
  180.  *-----------------------------------------------------------------------
  181.  * spriteBW2Init --
  182.  *    Attempt to initialize a bw2 framebuffer
  183.  *
  184.  * Results:
  185.  *    None
  186.  *
  187.  * Side Effects:
  188.  *    Most of the elements of the ScreenRec are filled in.  The
  189.  *    video is enabled for the frame buffer...
  190.  *
  191.  *-----------------------------------------------------------------------
  192.  */
  193. static Bool
  194. spriteBW2Init (index, pScreen, argc, argv)
  195.     int              index;        /* The index of pScreen in the ScreenInfo */
  196.     ScreenPtr      pScreen;      /* The Screen to initialize */
  197.     int              argc;            /* The number of the Server's arguments. */
  198.     char          **argv;       /* The arguments themselves. Don't change! */
  199. {
  200.     xColorItem      def;
  201.     ColormapPtr      pColormap;
  202.     
  203.     
  204.     if (!mfbScreenInit(index, pScreen, spriteFbs[index].fb,
  205.                BW2_WIDTH, BW2_HEIGHT, 90, 90)) {
  206.                return (FALSE);
  207.     }
  208.  
  209.     pScreen->SaveScreen = spriteBW2SaveScreen;
  210.     pScreen->ResolveColor = spriteBW2ResolveColor;
  211.     pScreen->CreateColormap = spriteBW2CreateColormap;
  212.     pScreen->DestroyColormap = spriteBW2DestroyColormap;
  213.     pScreen->whitePixel = 0;
  214.     pScreen->blackPixel = 1;
  215.  
  216.     /*
  217.      * Play with the default colormap to reflect that suns use 1 for black
  218.      * and 0 for white...
  219.      */
  220.     if ((CreateColormap(pScreen->defColormap, pScreen,
  221.             LookupID(pScreen->rootVisual, RT_VISUALID, RC_CORE),
  222.             &pColormap, AllocNone, 0) != Success) ||
  223.     (pColormap == NULL)) {
  224.         FatalError("Can't create colormap in spriteBW2Init()\n");
  225.     }
  226.     mfbInstallColormap(pColormap);
  227.  
  228.     /*
  229.      * Enable video output...? 
  230.      */
  231.     spriteBW2SaveScreen(pScreen, SCREEN_SAVER_OFF);
  232.  
  233.     spriteScreenInit(pScreen);
  234.     return (TRUE);
  235. }
  236.  
  237. /*-
  238.  *-----------------------------------------------------------------------
  239.  * spriteBW2Probe --
  240.  *    Attempt to find and map a bw2 framebuffer
  241.  *
  242.  * Results:
  243.  *    None
  244.  *
  245.  * Side Effects:
  246.  *    Memory is allocated for the frame buffer and the buffer is mapped. 
  247.  *
  248.  *-----------------------------------------------------------------------
  249.  */
  250. Bool
  251. spriteBW2Probe(screenInfo, index, fbNum, argc, argv)
  252.     ScreenInfo      *screenInfo;    /* The screenInfo struct */
  253.     int              index;        /* The index of pScreen in the ScreenInfo */
  254.     int              fbNum;        /* The SUN frame buffer number */
  255.     int              argc;            /* The number of the Server's arguments. */
  256.     char          **argv;       /* The arguments themselves. Don't change! */
  257. {
  258.     if(strlen(argv[0]) < 4 || strcmp("Xmfb", argv[0]+strlen(argv[0])-4) != 0)
  259.     return FALSE;
  260.  
  261.     if (!spriteFbs[index].mapped) {
  262.     pointer          pBigFb;
  263.     Sys_MachineInfo    machType;
  264.     Address          vidAddr;
  265.     unsigned int    size;
  266.  
  267.     size = (sizeof(BW2Rec) + VMMACH_SEG_SIZE - 1) / VMMACH_SEG_SIZE;
  268.     size *= VMMACH_SEG_SIZE;
  269.     pBigFb = (pointer) malloc(size + VMMACH_SEG_SIZE);
  270.  
  271.     if (Sys_GetMachineInfo (sizeof (machType), &machType) != SUCCESS) {
  272.         return FALSE;
  273.     }
  274.     if (machType.architecture == SYS_SUN2) {
  275.        vidAddr = (Address)0xec0000;
  276.     } else if (machType.architecture == SYS_SUN3) {
  277.         vidAddr = (Address)0xfe20000;
  278.     } else if (machType.architecture == SYS_SUN4) {
  279.         if (machType.type == SYS_SUN_4_C) {
  280.         vidAddr = (Address)0xffd80000;    /* sparc station */
  281.         } else {
  282.         vidAddr = (Address)0xffd40000;    /* regular sun4 */
  283.         }
  284.     } else {
  285.         return FALSE;
  286.     }
  287.  
  288.     if (Vm_MapKernelIntoUser (vidAddr, size, pBigFb,
  289.         &spriteFbs[index].fb) != SUCCESS) {
  290.           free ((char *) pBigFb);
  291.           return (FALSE);
  292.     }
  293.     spriteFbs[index].mapped = TRUE;
  294.     }
  295.     if (AddScreen (spriteBW2Init, argc, argv) > index) {
  296.     screenInfo->screen[index].CloseScreen = spriteBW2CloseScreen;
  297.     return TRUE;
  298.     } else {
  299.     return FALSE;
  300.     }
  301. }
  302.